﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hack
{
    public static class RandomGenerator
    {
        /// <summary>
        /// Generates a random string with the given length
        /// </summary>
        /// <param name="size">Size of the string</param>
        /// <param name="lowerCase">If true, generate lowercase string</param>
        /// <returns>Random string</returns>
        public static string RandomString(int size, bool lowerCase)
        {
            StringBuilder builder = new StringBuilder();
            Random random = new Random();
            char ch;
            for (int i = 0; i < size; i++)
            {
                ch = Convert.ToChar(Convert.ToInt32(System.Math.Floor(26 * random.NextDouble() + 65)));
                builder.Append(ch);
            }
            if (lowerCase)
                return builder.ToString().ToLower();
            return builder.ToString();
        }
        public static int RandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max);
        }
        /// <summary>
        /// Creates a password that nobody knows, not even you
        /// </summary>
        /// <param name="intPasswordLength"></param>
        /// <returns></returns>
        public static String RandomTemporaryPassword(int intPasswordLength)
        {

            Random rndmRandom = new Random();

            StringBuilder sbPassword = new StringBuilder();

            while (sbPassword.Length < intPasswordLength)
            {

                int intRandomValue = 0;

                while (intRandomValue == 0)
                {

                    intRandomValue = rndmRandom.Next(65, 90); // UpperCase Letters Only

                    if (intRandomValue == 73) intRandomValue = 0; // Don't allow "I" because it looks too much like a one (1)

                    if (intRandomValue == 79) intRandomValue = 0; // Don't allow "O" because it looks too much like a zero (0)

                }

                sbPassword.Append((Char)intRandomValue);

            }

            return sbPassword.ToString();

        }
    }
}
